package com.ht.modules.system.controller;

import com.ht.entity.Result;
import com.ht.utils.AppPushUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/pushmessage")
@Api(tags = "APP发送消息")
public class AppPushMessageController {

	@ApiOperation("给单人发送")
    @GetMapping("/toSingle")
	public Result<String> toSingle(@RequestParam(name = "title") String title,
                                   @RequestParam(name = "content") String content,
                                   @RequestParam(name = "cid") String cid) {
		Result<String> result = new Result<>();
		String pushMessageToSingle = AppPushUtil.pushMessageToSingle(title, content, cid);
		result.setSuccess(true);
		result.setMessage(pushMessageToSingle);
		return result;
	}

	@ApiOperation("给多人发送")
    @GetMapping(value = "/toList")
	public Result<String> pushMessageToList(@RequestParam(name = "title") String title,
                                            @RequestParam(name = "content") String content,
                                            @RequestParam(name = "cids") String cids) {
		String[] split = cids.split(",");
		List<String> cidList = Arrays.asList(split);
		Result<String> result = new Result<>();
		String pushMessageToList = AppPushUtil.pushMessageToList(title, content, cidList);
		result.setSuccess(true);
		result.setMessage(pushMessageToList);
		return result;
	}

	@ApiOperation("给所有人发送")
    @GetMapping(value = "/toAll")
	public Result<String> toAll(@RequestParam(name = "title") String title,
                                @RequestParam(name = "content") String content) {
		Result<String> result = new Result<>();
		String pushMessageToAll = AppPushUtil.pushMessageToAll(title, content);
		result.setSuccess(true);
		result.setMessage(pushMessageToAll);
		return result;
	}

}
